package com.explorati.set.leetcode804;

import java.util.Set;
import java.util.TreeSet;

/**
 * 804. Unique Morse Code Words Example: Input: words = ["gin", "zen", "gig",
 * "msg"] Output: 2 Explanation: The transformation of each word is: "gin" ->
 * "--...-." "zen" -> "--...-." "gig" -> "--...--." "msg" -> "--...--."
 * 
 * @author explorati
 *
 */
class Solution {
	public int uniqueMorseRepresentations(String[] words) {
		String[] codes = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
				"-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
		Set<String> set = new TreeSet<String>();

		for (String word : words) {
			StringBuilder res = new StringBuilder();
			for (int i = 0; i < word.length(); i++) {
				res.append(codes[word.charAt(i) - 'a']);
			}
			set.add(res.toString());
		}

		return set.size();
	}
}